package com.mljr.example.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.ctakit.sdk.app.base.BaseFragment;
import com.ctakit.sdk.app.base.BaseModel;
import com.ctakit.sdk.app.base.BasePresenter;
import com.ctakit.sdk.app.utils.ViewUtil;
import com.mljr.example.R;
import com.mljr.example.ui.h5.Html5Activity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <p/>
 * Created by andyhome on 16/05/20.
 */
public abstract class MyBaseFragment<T extends BasePresenter, E extends BaseModel> extends BaseFragment<T, E> implements AMapLocationListener {

    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;


    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = super.onCreateView(inflater, container, savedInstanceState);
        return v;
    }


    ///和MyBaseActivity 基本 一样 （修改时记得改MyBaseActivity） start
    public void initTitle(String title) {
        ViewUtil.setTextView(getFragment().getView(), Config.Server.getTitle(Global.getDevModel(), title), R.id.theme_title);
    }

    public void initBack(String label) {
        BaseUtil.initBack(this, label);
    }


    public void initBack() {
        initBack("");
    }

    public void gotoHtml5Activity(String url) {
        Map<String, Serializable> data = new HashMap<String, Serializable>();
        data.put("url", url);
        gotoActivity(Html5Activity.class, data);
    }


    //启动定位
    protected void initLocation() {
        //初始化定位
        mLocationClient = BaseUtil.initLocation(this);
        //启动定位
        mLocationClient.startLocation();
    }


    public void onLocationChanged(AMapLocation amapLocation) {
        BaseUtil.onLocationChanged(amapLocation, mLocationClient);
    }
    ///和MyBaseActivity 基本 一样 （修改时记得改MyBaseActivity） end


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mLocationClient != null) {
            mLocationClient.onDestroy();//销毁定位客户端
        }
    }


}


